﻿using System;
using System.Collections.Generic;
using System.Text;
using Dongzr.MidiLite;
using System.Threading;
using System.Diagnostics;

namespace MmTimerTest
{
    class Program
    {
        static int timer1Tick = 0,timer2Tick = 0, mainTick = 0;
        static MmTimer timer1,timer2;
        static PerformanceCounter pc;
        static float rate;
        static void Main(string[] args)
        {
            pc = new PerformanceCounter("Processor","% Processor Time","_Total");
            timer1 = new MmTimer();
            timer1.Mode = MmTimerMode.Periodic;
            timer1.Interval = 1;
            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Start();
            timer2 = new MmTimer();
            timer2.Mode = MmTimerMode.Periodic;
            timer2.Interval = 1;
            timer2.Tick += new EventHandler(timer2_Tick);
            timer2.Start();
            Console.WriteLine(timer1.IsRunning.ToString());
            while(!Console.KeyAvailable)
            {
                mainTick++;
                rate = pc.NextValue();
                Thread.Sleep(100);
            }
            timer1.Stop();
            timer2.Stop();
            timer1.Dispose();
            timer2.Dispose();
        }

        static void timer1_Tick(object sender, EventArgs e)
        {
            timer1Tick++;
            Console.WriteLine("timer1Tick:\t" + timer1Tick.ToString() + "\tmainTick:" + mainTick.ToString() + "\tCPU using rate:" + rate.ToString() + "%");
            for (int i = 0; i < 500; i++)
            {
                float temp = 1.123f;
                temp = temp + 1.456f - 2.789f;
                temp = temp * 2.147f / 8.852f;

            }
        }

        static void timer2_Tick(object sender, EventArgs e)
        {
            timer2Tick++;
            Console.WriteLine("timer2Tick:\t" + timer2Tick.ToString() + "\tmainTick:" + mainTick.ToString() + "\tCPU using rate:" + rate.ToString() + "%");
            for (int i = 0; i < 1000; i++)
            {
                float temp = 1.123f;
                temp = temp + 1.456f - 2.789f;
                temp = temp * 2.147f / 8.852f;
            }
        }
    }
}
